<?php
/**
 * 好物爆料预埋数据
 * php cli/Crond/FineGoodsBrokeNews/EmbeddedData.php
 * php cli/Crond/FineGoodsBrokeNews/EmbeddedData.php uid noteList wikiList
 * php cli/Crond/FineGoodsBrokeNews/EmbeddedData.php 10001 '["000nbp400000nbms"]' '[{"comment": "c12a930e1e0623e13a12", "basic_id": "111"}]'
 * php cli/Crond/FineGoodsBrokeNews/EmbeddedData.php 10001 -n='000nbp400000nbms 000nbp400000nbms'
 * php cli/Crond/FineGoodsBrokeNews/EmbeddedData.php 10001 -w='[{"comment": "c12a930e1e0623e13a12", "basic_id": "111"}]'
 * php cli/Crond/FineGoodsBrokeNews/EmbeddedData.php 10001 -n='000nbp400000nbms 000nbp400000nbms' -w='[{"comment": "c12a930e1e0623e13a12", "basic_id": "111"}]'
 */

use Biz\service\FineGoodsBrokeNews\FineGoodsBrokeNewsService;

ini_set('display_errors', 1);            //错误信息
ini_set('display_startup_errors', 1);    //php启动错误信息
error_reporting(-1);                    //打印出所有的 错误信息
ini_set('memory_limit', '1024M');
require_once '/data/wwwroot/g_vendor/autoload.php';

function init(array $args = []): array
{
    $uid = $args[1];
    $note = "";
    $wiki = "";
    $char = 0;
    foreach ($args as $arg) {
        if(strpos($arg,"-w=") !== false){
            $wiki = str_replace("-w=","",$arg);
            $char++;
        }else if(strpos($arg,"-t=") !== false){
            $note = str_replace("-t=","",$arg);
            $char++;
        }
    }
    if($char == 0){
        $note = $args[2];
        $wiki = $args[3];
    }
    if(!empty($note)){
        $note = explode(" ",$note);
    }
    return [$uid, $note, $wiki];
}

if (count($argv) >= 2) {
    list($uid, $note, $wiki) = init($argv);
    if (!empty($wiki)) {
        FineGoodsBrokeNewsService::saveData([
            'uid' => $uid,
            'data' => $wiki
        ]);
    }
    if (!empty($note)) {
        foreach ($note as $index => $item) {
            FineGoodsBrokeNewsService::addNoteLog([
                'uid' => $uid,
                'id' => $item
            ]);
            sleep(1);
        }
    }
    echo '数据添加成功' . PHP_EOL;
} else {
    $json = [
        ['39090' , '005cubd00000nh5s'],
        ['56543' , '005ct5u00007q469'],
        ['97044' , '005csof000002fh1'],
        ['113365' , '005crwi000000u5u'],
        ['157380' , '005cqqk000003dfo'],
        ['433345' , '005cqmu00007q42e'],
        ['486635' , '005cqcn00003gtil'],
        ['798727' , '005crgp0000022vo'],
        ['1095328' , '005cnlu00002gzrw'],
        ['1304810' , '005cm1h0000162ar'],
        ['1962531' , '005ck0y00006uoai'],
        ['3232562' , '005cjnk00001xa9e'],
        ['4152092' , '005cj3s0000017mn'],
        ['5823597' , '005cfjn00000rysq'],
        ['11508858' , '005cdmr000009add'],
        ['12975638' , '005cd9700000h4av'],
        ['174930' , '005crwh000003qz6'],
        ['165077' , '005crk6000003jdh'],
        ['12975777' , '005ct4v00007q469'],
        ['486635' , '005cs5300000afhn'],
    ];
    foreach ($json as $item) {
        FineGoodsBrokeNewsService::addNoteLog([
            'uid' => $item[0],
            'id' => $item[1]
        ]);
        sleep(1);
    }
    echo '数据添加成功' . PHP_EOL;
}